﻿using System.Windows;
using HRM.ViewModel;
using System.Windows.Navigation;
using GalaSoft.MvvmLight.Messaging;
using HRM.Converter;
using System.Windows.Media;
using GalaSoft.MvvmLight.Ioc;
using HRM.Helper;
using System;

namespace HRM
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window
    {
        /// <summary>
        /// Initializes a new instance of the MainWindow class.
        /// </summary>
        public MainWindow()
        {
            InitializeComponent();
            Closing += (s, e) => ViewModelLocator.Cleanup();
            this.Closed += MainWindow_Closed;
            double screenHeight = SystemParameters.FullPrimaryScreenHeight;
            double screenWidth = SystemParameters.FullPrimaryScreenWidth;
            this.Top = (screenHeight - this.Height) / 2;
            this.Left = (screenWidth - this.Width) / 2;
        }

        void MainWindow_Closed(object sender, System.EventArgs e)
        {
            Messenger.Default.Unregister<StatusMessage>(this, HandleStatusMessage);
        }

        private void Exit_Click(object sender, RoutedEventArgs e)
        {
            Application.Current.Shutdown();
        }

        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            Messenger.Default.Register<StatusMessage>(this, HandleStatusMessage);
        }

        public void HandleStatusMessage(StatusMessage msg)
        {
            Status.Message = msg.Status;
            Status.IconSource = msg.IconSource;
            Status.Show(msg.TimeoutMilliseconds);
        }

        private void Logout_Click(object sender, RoutedEventArgs e)
        {
            System.Windows.Forms.Application.Restart();
            Application.Current.Shutdown();
        }
    }
}